package cn.yangliu.service.impl;

import cn.yangliu.entity.SettingDetail;
import cn.yangliu.jpa.base.service.impl.JpaServiceImpl;
import cn.yangliu.repository.SettingDetailRepository;
import cn.yangliu.service.SettingDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author 问道于盲
 * @date 2021-09-28
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class SettingDetailServiceImpl extends JpaServiceImpl<SettingDetail, Long, SettingDetailRepository> implements SettingDetailService {

    /**
     * 根据配置id查询配置详细信息
     *
     * @param settingId 配置id
     * @return 配置详细信息
     */
    @Override
    public SettingDetail findBySettingId(Long settingId) {
        Optional<SettingDetail> optional = repository.findBySettingId(settingId);
        return optional.orElse(SettingDetail.DEFAULT);
    }

    /**
     * 根据配置id删除配置详细
     *
     * @param settingId 配置id
     */
    @Override
    public void deleteBySettingId(Long settingId) {
        repository.deleteBySettingId(settingId);
    }
}
